<?php

/*
 * litchicms
 * Copyright (C) 2010-5-1 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");

/*
 * template_parse_dot2quote 
 * @param $string 
 * @return $string
 */

function template_parse_dot2quote($string) {
    //{if $key==$RT['v']['m']}class="list"{/if}><a href="{$item[1]}">{$item[0]}<
    //"{if $key==$RT['v']['m']}"
    // [3] => string(10) "{$item[1]}"
    // [4] => string(10) "{$item[0]}"
    /// [5] => string(22) "{foreach from="$NAVI"}"
    //[6] => string(18) "{if $key==$RT.v.m}"
    //  [7] => string(10) "{$item[1]}"
//    [8] => string(9) "{$item.0}"

    $all_base = array();
    preg_match_all("/\{([^\/\\\\].*?)\}/is", $string, $all_base);
    $re = $all_base[0];
    foreach ($all_base[0] as &$v) {
        preg_match_all("/(\.\w*)?/", $v, $matchesarray);
        $matchesarray[0] = array_filter($matchesarray[0]);
        $matchesarray[1] = array_filter($matchesarray[0]);
        foreach ($matchesarray[1] as $k => &$value) {
            if ($value != '.this') {
                $value = substr($value, 1);
                $value = "['$value']";
            }
            $matchesarray[0][$k] = "/" . preg_quote($matchesarray[0][$k], '/') . "/";
        }
        unset($value);
        $v = preg_replace($matchesarray[0], $matchesarray[1], $v, 1);
    }
    unset($v);
    foreach ($re as &$v) {
        $v = "/" . preg_quote($v, '/') . "/";
    }
    unset($v);
    $string = preg_replace($re, $all_base[0], $string, 1);

    return $string;
}
?>
